home *** CD-ROM | disk | FTP | other *** search
-
- {*******************************************************}
- { }
- { Delphi Visual Component Library }
- { }
- { Copyright (c) 1995,97 Borland International }
- { }
- {*******************************************************}
-
- unit ToolWin;
-
- {$P+,S-,W-,R-}
- {$C PRELOAD}
-
- interface
-
- uses Windows, Messages, Classes, Controls, Forms;
-
- type
-
- { TToolWindow }
-
- TToolWindow = class(TWinControl)
- private
- FBorderStyle: TBorderStyle;
- FBorderWidth: Integer;
- FMargin: Integer;
- procedure SetBorderStyle(Value: TBorderStyle);
- procedure SetBorderWidth(Value: Integer);
- procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
- procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
- procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
- protected
- procedure CreateParams(var Params: TCreateParams); override;
- public
- constructor Create(AOwner: TComponent); override;
- property Ctl3D;
- property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
- property BorderWidth: Integer read FBorderWidth write SetBorderWidth default 0;
- end;
-
- implementation
-
- { TToolWindow }
-
- constructor TToolWindow.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FBorderStyle := bsSingle;
- end;
-
- procedure TToolWindow.CreateParams(var Params: TCreateParams);
- begin
- inherited CreateParams(Params);
- if BorderStyle = bsSingle then
- if Ctl3D then
- FMargin := 2
- else
- begin
- FMargin := 1;
- Params.Style := Params.Style or WS_BORDER;
- end
- else
- FMargin := 0;
- end;
-
- procedure TToolWindow.SetBorderStyle(Value: TBorderStyle);
- begin
- if FBorderStyle <> Value then
- begin
- FBorderStyle := Value;
- RecreateWnd;
- end;
- end;
-
- procedure TToolWindow.SetBorderWidth(Value: Integer);
- begin
- if FBorderWidth <> Value then
- begin
- FBorderWidth := Value;
- RecreateWnd;
- end;
- end;
-
- procedure TToolWindow.WMNCCalcSize(var Message: TWMNCCalcSize);
- begin
- InflateRect(Message.CalcSize_Params.rgrc[0], -(FBorderWidth + FMargin),
- -(FBorderWidth + FMargin));
- inherited;
- end;
-
- procedure TToolWindow.WMNCPaint(var Message: TMessage);
- var
- DC: HDC;
- RC, RW: TRect;
- begin
- { Get window DC that is clipped to the non-client area }
- DC := GetWindowDC(Handle);
- try
- Windows.GetClientRect(Handle, RC);
- GetWindowRect(Handle, RW);
- MapWindowPoints(0, Handle, RW, 2);
- OffsetRect(RC, -RW.Left, -RW.Top);
- ExcludeClipRect(DC, RC.Left, RC.Top, RC.Right, RC.Bottom);
- { Draw borders in non-client area }
- OffsetRect(RW, -RW.Left, -RW.Top);
- { Erase background }
- InflateRect(RW, -FMargin, -FMargin);
- FillRect(DC, RW, Brush.Handle);
- InflateRect(RW, FMargin, FMargin);
- if Ctl3D and (BorderStyle = bsSingle) then
- begin
- DrawEdge(DC, RW, EDGE_ETCHED, BF_RECT);
- InflateRect(RW, -FMargin, -FMargin);
- end;
- { Erase parts not drawn }
- IntersectClipRect(DC, RW.Left, RW.Top, RW.Right, RW.Bottom);
- finally
- ReleaseDC(Handle, DC);
- end;
- inherited;
- end;
-
- procedure TToolWindow.CMCtl3DChanged(var Message: TMessage);
- begin
- inherited;
- if FBorderStyle = bsSingle then RecreateWnd;
- end;
-
- end.
-